<template>
    <div class="sidebar">
        <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
            text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
                            <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                        </template>
                        <el-menu-item v-for="(subItem,i) in item.subs" :key="i" :index="subItem.index">
                            <div class="child-radio"></div>
                            <!--<div class="child-radio-active"></div>-->
                            <span class="child-text">{{ subItem.title }} </span>
                        </el-menu-item>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
    import bus from '../common/bus';
    export default {
        data() {
            return {
                collapse: false,
                items: [
                    {
                        icon: 'el-icon-setting',
                        index: 'dashboard',
                        title: '首页'
                    },
                    {
                        icon: 'el-icon-message',
                        index: 'tabs',
                        title: '访问控制'
                    },
                    {
                        icon: 'el-icon-date',
                        index: '3',
                        title: 'B/S访问控制',
                        subs: [
                            {
                                index: 'form',
                                title: '网关配置'
                            },
                            {
                                index: 'editor',
                                title: '服务配置'
                            },
                            {
                                index: 'markdown',
                                title: 'markdown编辑器'
                            },
                            {
                                index: 'upload',
                                title: '文件上传'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-star-on',
                        index: 'charts',
                        title: 'C/S访问控制',
                        subs: [

                            {
                                index: 'editor',
                                title: '服务配置'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-rank',
                        index: 'drag',
                        title: '代理配置',
                        subs: [
                            {
                                index: 'form',
                                title: 'web代理'
                            },
                            {
                                index: 'editor',
                                title: '应用代理'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-warning',
                        index: 'permission',
                        title: '文件交换',
                        subs: [
                            {
                                index: 'form',
                                title: '有效性配置'
                            },
                            {
                                index: 'editor',
                                title: '服务配置'
                            },
                            {
                                index: 'markdown',
                                title: '文件交换记录'
                            },
                            {
                                index: 'upload',
                                title: '空间清理'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-time',
                        index: 'systemmanage',
                        title: '系统配置',
                        subs: [
                            {
                                index: 'menu',
                                title: '菜单列表'
                            },
                            {
                                index: 'form',
                                title: '网卡管理'
                            },
                            {
                                index: 'editor',
                                title: '状态查看'
                            },
                            {
                                index: 'markdown',
                                title: '账号管理'
                            },
                            {
                                index: 'upload',
                                title: '配置文件管理'
                            },
                            {
                                index: 'admin',
                                title: '日志审计设置'
                            },
                            {
                                index: 'role',
                                title: 'DNS配置'
                            },
                            {
                                index: 'registuser',
                                title: '路由表配置'
                            },
                            {
                                index: 'markdown',
                                title: '文件交换记录'
                            },
                            {
                                index: 'upload',
                                title: '空间清理'
                            },
                            {
                                index: 'markdown',
                                title: '默认网关配置'
                            },
                            {
                                index: 'upload',
                                title: '更新设置'
                            }

                        ]
                    },
                    {
                        icon: 'el-icon-message',
                        index: 'tabs',
                        title: '前后置通信配置'
                    },
                    {
                        icon: 'el-icon-time',
                        index: 'systemmanage1',
                        title: '日志审计',
                        subs: [
                            {
                                index: 'menu',
                                title: '文件交换日志'
                            },
                            {
                                index: 'form',
                                title: '访问控制日志'
                            },
                            {
                                index: 'editor',
                                title: '代理访问日志'
                            },
                            {
                                index: 'markdown',
                                title: 'URL过滤日志'
                            },
                            {
                                index: 'upload',
                                title: '人员策略访问日志'
                            }

                        ]
                    },
                    {
                        icon: 'el-icon-error',
                        index: '404',
                        title: '404页面'
                    },
                    // online menu
                    {
                        icon: 'el-icon-star-on',
                        src:'static/img/icon1.png',
                        index: 'home',
                        title: '首页'
                    },
                    {
                        icon: 'el-icon-tickets',
                        icon: 'el-icon-error',
                        index: 'logmanage',
                        title: '日志系统',
                        subs: [
                            {
                                index: 'log',
                                title: '日志列表'
                            }
                        ]
                    },

                    {
                        icon: 'el-icon-star-on',
                        index: 'useramanger',
                        title: '用户管理',
                        subs: [
                            {
                                index: 'admin',
                                title: '后台管理员'
                            },
                            {
                                index: 'role',
                                title: '后台管理员'
                            },
                            {
                                index: 'registuser',
                                title: '注册用户'
                            }
                        ]
                    }
                ]
            }
        },
        computed:{
            onRoutes(){

                return this.$route.path.replace('/','');
                // return 'dashboard';
            }
        },
        created(){
            // 通过 Event Bus 进行组件间通信，来折叠侧边栏
            bus.$on('collapse', msg => {
                this.collapse = msg;
            })
        }
    }
</script>

<style scoped>
    .sidebar{
        display: block;
        position: absolute;
        left: 0;
        top: 70px;
        bottom:0;
        overflow-y: scroll;
    }
    .sidebar::-webkit-scrollbar{
        width: 0;
    }
    .sidebar-el-menu:not(.el-menu--collapse){
        /*width: 250px;*/
        width: 247px;
    }
    .sidebar > ul {
        height:100%;
    }
  /*  .sidebar .child-radio-active{
        height: 4px;
        width: 4px;
        border-radius: 4px;
        background-color: white;
        display: inline-block;
    }*/
    .sidebar .child-radio{
        height: 3px;
        width: 3px;
        border-radius: 3px;
        background-color: #313743;
        border: 1px solid #6c7583;
        display: inline-block;
    }
</style>
